<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>

    <script src="../static/js/jquery/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="../static/layui/layui.js" type="text/javascript"></script>
    <script src="../static/js/index/index.js" type="text/javascript"></script>
    <script src="../static/js/index/freezeheader.js" type="text/javascript"></script>
    <script src="../static/layui/lay/modules/layer.js" type="text/javascript"></script>
    <script src="../static/js/index/sliders.js" type="text/javascript"></script>
    <script src="../static/js/index/html5.js" type="text/javascript"></script>
    <link rel="stylesheet" href="../static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../static/layui/css/modules/layer/default/layer.css"/>
    <link rel="stylesheet" href="../static/css/global.css"/>
    <link rel="stylesheet" href="./css/amazeui.min.css"/>
    <link rel="stylesheet" href="./css/admin.css"/>
    <link rel="stylesheet"
          href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <%--<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>--%>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script
            src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <link rel="stylesheet" type="text/css"
          href="https://www.layuicdn.com/layui/css/layui.css"/>

    <script type="text/javascript" src="js/layer.js"></script>
    <link rel="stylesheet" href="css/layer.css">
</head>

<script type="text/javascript">
</script>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">学生管理</strong>
            <small></small>
        </div>
    </div>
    <hr>
    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <%--<a href="javascript:void(0)" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                       onclick="updatePwd('新增')">新增</a>--%>

                    <a <%--onclick="editMessage(${student.studentId});"--%>
                            class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                            href="/admin/student/jump">新增</a>
                </div>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-4">
            <div class="layui-form-item">
                <div class="layui-input-inline" style="width:65%;">
                    <input type="text" id="keyName" name="keyContent" lay-verify="required" placeholder="请输入关键字"
                           class="layui-input">
                </div>
                <button class="layui-btn" onclick="getMessage();">搜索</button>
            </div>
        </div>
    </div>
    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-id">学生ID</th>
                        <th class="table-title">学生学号</th>
                        <th class="table-type">学生姓名</th>
                        <th class="table-author am-hide-sm-only">学生性别</th>
                        <th class="table-date am-hide-sm-only">学生所学专业</th>
                        <th class="table-set">学生所属班级</th>
                        <th class="table-id">学生手机号</th>
                        <th class="table-set">操作</th>
                    </tr>
                    </thead>
                    <tbody id="result">
                    <c:forEach items="${students}" var="student">
                        <tr>
                            <td class="table-type">${student.studentId}</td>
                            <td class="am-hide-sm-only">${student.studentNumber}</td>
                            <td class="am-hide-sm-only">${student.studentName}</td>
                            <c:set var="cnt" scope="session"
                                   value="${student.studentSex}"></c:set>

                            <c:if test="${cnt==0}">
                                <td class="am-hide-sm-only">男</td>
                            </c:if>
                            <c:if test="${cnt==1}">
                                <td class="am-hide-sm-only">女</td>
                            </c:if>

                            <td class="am-hide-sm-only">${student.studentSpecialty}</td>
                            <td class="am-hide-sm-only">${student.studentClass}</td>
                            <td class="am-hide-sm-only">${student.studentTel}</td>
                            <td>
                                <div class="am-btn-toolbar" >
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a <%--onclick="editMessage(${student.studentId});"--%>
                                           class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                           href="/admin/updStudent/${student.studentNumber}">编辑</a>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <dd>
                                        </dd>
                                        <a onclick="delStudent(${student.studentId})">删除</a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>

                <hr>
            </form>
        </div>
    </div>
</div>
<script>
    function editMessage() {

    }
</script>
<script>
    var nowdatas;
    var inputName;

    function getMessage() {
        inputName = $("#keyName").val();
        $.ajax({
                type: "get",
                url: "/admin/student/search",
                data: {"keyContent": inputName},
                dataType: 'json',
                success: function (data) {
                    if (data.length == 0) {
                        alert("没有搜索到对应的内容");
                    }
                    nowdatas = data;

                    add();
                }
            }
        )
    }

    function add() {
        $('#result').empty();
        for (var i = 0; i < nowdatas.length; i++) {
            str1 = '<tr><td>' + (i + 1) + '</td><td>' +
                nowdatas[i]['studentNumber']
                + '</td><td>' +
                nowdatas[i]['studentName']
                + '</td><td>' +
                nowdatas[i]['studentSex']
                + '</td><td>' +
                nowdatas[i]['studentSpecialty']
                + '</td><td>' +
                nowdatas[i]['studentClass']
                + '</td><td>' +
                nowdatas[i]['studentTel']
                + '</td><td></td><td><div class="am-btn-toolbar" ><div class="am-btn-group am-btn-group-xs"><a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" href="/admin/updStudent/' + nowdatas[i]['studentNumber'] + '">编辑</a></div></div></td><td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><dd></dd><a href="/student/del/' + nowdatas[i]['studentId'] + '">删除</a></div></div></td>' +
                +'</tr>';
            $('#result').append(str1);
        }
    }

    function delStudent(studentId) {
        inputName = studentId;
        $.ajax({
                type: "get",
                url: "/student/del",
                data: {"studentId": inputName},
                dataType: 'json',
                success: function (data) {
                    //  location.reload();
                    parent.location.reload();
                    alert("删除成功！");
                }
            }
        )
    }
</script>
</body>
<%--<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>--%>
<script type="text/javascript" src="myplugs/js/plugs.js">
</script>
<script type="text/javascript">
    //添加编辑弹出层
    function updatePwd(title) {
        $.jq_Panel({
            title: title,
            iframeWidth: 500,
            iframeHeight: 800,
            url: "studentSet.jsp"
        });
        // parent.location.reload();
    }
</script>
<script src="js/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function () {
        var element = layui.element;

    });
</script>

</html>